package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.PayablePlan;
import com.ruoyi.erp.service.IPayablePlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 付款计划Controller
 * 
 * @author sauger
 * @date 2022-04-04
 */
@Controller
@RequestMapping("/erp/payable/plan")
public class PayablePlanController extends BaseController
{
    private String prefix = "erp/payable/plan";

    @Autowired
    private IPayablePlanService payablePlanService;

    @RequiresPermissions("erp:payable:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询付款计划列表
     */
    @RequiresPermissions("erp:payable:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayablePlan payablePlan)
    {
        startPage();
        List<PayablePlan> list = payablePlanService.selectPayablePlanList(payablePlan);
        return getDataTable(list);
    }

    /**
     * 导出付款计划列表
     */
    @RequiresPermissions("erp:payable:plan:export")
    @Log(title = "付款计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayablePlan payablePlan)
    {
        List<PayablePlan> list = payablePlanService.selectPayablePlanList(payablePlan);
        ExcelUtil<PayablePlan> util = new ExcelUtil<PayablePlan>(PayablePlan.class);
        return util.exportExcel(list, "付款计划数据");
    }

    /**
     * 新增付款计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存付款计划
     */
    @RequiresPermissions("erp:payable:plan:add")
    @Log(title = "付款计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayablePlan payablePlan)
    {
        return toAjax(payablePlanService.insertPayablePlan(payablePlan));
    }

    /**
     * 修改付款计划
     */
    @RequiresPermissions("erp:payable:plan:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        PayablePlan payablePlan = payablePlanService.selectPayablePlanById(id);
        mmap.put("payablePlan", payablePlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存付款计划
     */
    @RequiresPermissions("erp:payable:plan:edit")
    @Log(title = "付款计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayablePlan payablePlan)
    {
        return toAjax(payablePlanService.updatePayablePlan(payablePlan));
    }

    /**
     * 删除付款计划
     */
    @RequiresPermissions("erp:payable:plan:remove")
    @Log(title = "付款计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(payablePlanService.deletePayablePlanByIds(ids));
    }
}
